Trò chơi Tic-Tac-Toe, game đánh caro full source code
53.530 lượt xem;
1 using System;
2
3 namespace Assets.Scripts.Signals
4 {
5 public class Signal
6 {
7 private event Action Listener = delegate { };
8 private event Action OnceListener = delegate { };
9
10 public void AddListener(Action callback)
11 {
12 Listener += callback;
13 }
14
15 public void AddOnce(Action callback)
16 {
17 OnceListener += callback;
18 }
19
20 public void RemoveListener(Action callback)
21 {
22 Listener -= callback;
23 }
24
25 public void Dispatch()
26 {
27 Listener();
28 OnceListener();
29 OnceListener = delegate { };
30 }
31 }
32
33 public class Signal<T>
34 {
35 private event Action<T> Listener = delegate { };
36 private event Action<T> OnceListener = delegate { };
37
38 public void AddListener(Action<T> callback)
39 {
40 Listener += callback;
41 }
42
43 public void AddOnce(Action<T> callback)
44 {
45 OnceListener += callback;
46 }
47
48 public void RemoveListener(Action<T> callback)
49 {
50 Listener -= callback;
51 }
52
53 public void Dispatch(T type1)
54 {
55 Listener(type1);
56 OnceListener(type1);
57 OnceListener = delegate { };
58 }
59 }
60
61 public class Signal<T, U>
62 {
63 private event Action<T, U> Listener = delegate { };
64 private event Action<T, U> OnceListener = delegate { };
65
66 public void AddListener(Action<T, U> callback)
67 {
68 Listener += callback;
69 }
70
71 public void AddOnce(Action<T, U> callback)
72 {
73 OnceListener += callback;
74 }
75
76 public void RemoveListener(Action<T, U> callback)
77 {
78 Listener -= callback;
79 }
80
81 public void Dispatch(T type1, U type2)
82 {
83 Listener(type1, type2);
84 OnceListener(type1, type2);
85 OnceListener = delegate { };
86 }
87 }
88
89 public class Signal<T, U, V>
90 {
91 private event Action<T, U, V> Listener = delegate { };
92 private event Action<T, U, V> OnceListener = delegate { };
93
94 public void AddListener(Action<T, U, V> callback)
95 {
96 Listener += callback;
97 }
98
99 public void AddOnce(Action<T, U, V> callback)
100 {
101 OnceListener += callback;
102 }
103
104 public void RemoveListener(Action<T, U, V> callback)
105 {
106 Listener -= callback;
107 }
108
109 public void Dispatch(T type1, U type2, V type3)
110 {
111 Listener(type1, type2, type3);
112 OnceListener(type1, type2, type3);
113 OnceListener = delegate { };
114 }
115 }
116
117 public class Signal<T, U, V, W>
118 {
119 private event Action<T, U, V, W> Listener = delegate { };
120 private event Action<T, U, V, W> OnceListener = delegate { };
121
122 public void AddListener(Action<T, U, V, W> callback)
123 {
124 Listener += callback;
125 }
126
127 public void AddOnce(Action<T, U, V, W> callback)
128 {
129 OnceListener += callback;
130 }
131
132 public void RemoveListener(Action<T, U, V, W> callback)
133 {
134 Listener -= callback;
135 }
136
137 public void Dispatch(T type1, U type2, V type3, W type4)
138 {
139 Listener(type1, type2, type3, type4);
140 OnceListener(type1, type2, type3, type4);
141 OnceListener = delegate { };
142 }
143 }
144 }
2
3 namespace Assets.Scripts.Signals
4 {
5 public class Signal
6 {
7 private event Action Listener = delegate { };
8 private event Action OnceListener = delegate { };
9
10 public void AddListener(Action callback)
11 {
12 Listener += callback;
13 }
14
15 public void AddOnce(Action callback)
16 {
17 OnceListener += callback;
18 }
19
20 public void RemoveListener(Action callback)
21 {
22 Listener -= callback;
23 }
24
25 public void Dispatch()
26 {
27 Listener();
28 OnceListener();
29 OnceListener = delegate { };
30 }
31 }
32
33 public class Signal<T>
34 {
35 private event Action<T> Listener = delegate { };
36 private event Action<T> OnceListener = delegate { };
37
38 public void AddListener(Action<T> callback)
39 {
40 Listener += callback;
41 }
42
43 public void AddOnce(Action<T> callback)
44 {
45 OnceListener += callback;
46 }
47
48 public void RemoveListener(Action<T> callback)
49 {
50 Listener -= callback;
51 }
52
53 public void Dispatch(T type1)
54 {
55 Listener(type1);
56 OnceListener(type1);
57 OnceListener = delegate { };
58 }
59 }
60
61 public class Signal<T, U>
62 {
63 private event Action<T, U> Listener = delegate { };
64 private event Action<T, U> OnceListener = delegate { };
65
66 public void AddListener(Action<T, U> callback)
67 {
68 Listener += callback;
69 }
70
71 public void AddOnce(Action<T, U> callback)
72 {
73 OnceListener += callback;
74 }
75
76 public void RemoveListener(Action<T, U> callback)
77 {
78 Listener -= callback;
79 }
80
81 public void Dispatch(T type1, U type2)
82 {
83 Listener(type1, type2);
84 OnceListener(type1, type2);
85 OnceListener = delegate { };
86 }
87 }
88
89 public class Signal<T, U, V>
90 {
91 private event Action<T, U, V> Listener = delegate { };
92 private event Action<T, U, V> OnceListener = delegate { };
93
94 public void AddListener(Action<T, U, V> callback)
95 {
96 Listener += callback;
97 }
98
99 public void AddOnce(Action<T, U, V> callback)
100 {
101 OnceListener += callback;
102 }
103
104 public void RemoveListener(Action<T, U, V> callback)
105 {
106 Listener -= callback;
107 }
108
109 public void Dispatch(T type1, U type2, V type3)
110 {
111 Listener(type1, type2, type3);
112 OnceListener(type1, type2, type3);
113 OnceListener = delegate { };
114 }
115 }
116
117 public class Signal<T, U, V, W>
118 {
119 private event Action<T, U, V, W> Listener = delegate { };
120 private event Action<T, U, V, W> OnceListener = delegate { };
121
122 public void AddListener(Action<T, U, V, W> callback)
123 {
124 Listener += callback;
125 }
126
127 public void AddOnce(Action<T, U, V, W> callback)
128 {
129 OnceListener += callback;
130 }
131
132 public void RemoveListener(Action<T, U, V, W> callback)
133 {
134 Listener -= callback;
135 }
136
137 public void Dispatch(T type1, U type2, V type3, W type4)
138 {
139 Listener(type1, type2, type3, type4);
140 OnceListener(type1, type2, type3, type4);
141 OnceListener = delegate { };
142 }
143 }
144 }